home *** CD-ROM | disk | FTP | other *** search
- #include "defs.h"
-
- #include <Traps.h>
- #include "patching.h"
- Boolean TrapAvailable( short trapnum );
-
- /*
- The tricky thing here is that as the final step of the clean-up,
- we want to deallocate the very handle containing this code. It is
- not safe for code to call DisposHandle on itself, since something
- like the Zap dcmd may be running. So we use a bit of trickery
- involving the ToolScratch area in low memory, which I saw in someone
- else's Notification Manager code.
- */
-
- #define ToolScratch 0x09CE // an 8-byte scratch area in low memory
-
- pascal void My_EndUpDate( void )
- {
- WindowPtr the_window;
-
- asm {
- HEAD_PATCH_HEADER( EndUpDate )
- move.L 8(A6), the_window
- }
-
- if (the_window == front)
- {
- End_copy(); // finish and clean up
- asm {
- LEA @save_h, A0 ; Copy this code's handle...
- move.L my_h, (A0) ; ...into @save_h
- move.L #ToolScratch, A0 ; Copy disposal code...
- move.L @dispos, (A0)
- move.W @rts, 4(A0) ; ...into ToolScratch
- }
- if (TrapAvailable(_HWPriv))
- FlushInstructionCache();
- asm {
- movem.L (SP)+, A0-A5/D0-D7 ; restore registers
- unlk A6
- move.L @0, -(SP) ; push real EndUpdate address
- move.L @save_h, -(SP) ; push handle to dispose
- move.L #ToolScratch, -(SP) ; push address of ToolScratch
- RTS ; go to ToolScratch
-
- @save_h dc.L 0
- @dispos move.L (SP)+, A0
- DisposHandle
- @rts RTS
- }
- }
-
- asm {
- HEAD_PATCH_FINISH
- }
- }